package 集合;

import org.omg.CORBA.PUBLIC_MEMBER;
import sun.reflect.generics.tree.Tree;

import java.util.*;

/*
public class Main {
    public static void main(String[] args)
    {
        Student x = new Student("xiaoming", 90); //创建学生实例对象
        Map<String, Student> map = new HashMap<>();  //新建hash
        map.put("1",x);
        Student target = map.get("1");
        System.out.println(target==x);
        System.out.println(target.name);
        System.out.println(target.score);
    }
}
class Student{
    public String name;
    public int score;
    public Student(String name,int score){
        this.name=name;
        this.score=score;
    }
}
*/

/*
map遍历是无序的
public class Main {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("apple", 123);
        map.put("pear", 456);
        map.put("banana", 789);
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key + " = " + value);
        }
    }
}
*/
public class Main {
    public static void main(String[] args) {

        TreeMap<Student, Integer> map = new TreeMap<>(new Comparator<Student>() {
            public int compare(Student p1,Student p2)
            {
                if (p1.score==p2.score)
                {
                    return 0;
                }
                return p1.score>p2.score ?-1:1;

            }
        });
        map.put(new Student("tom",77),5);
        map.put(new Student("bob",66),9);
        map.put(new Student("lily",99),4);
        for (Student key : map.keySet()) {
            System.out.println(key);
        }
        //System.out.println(map.get(new Student("bob",66))); //null?
    }
}

class Student{
    public String name;
    public int score;
    public Student(String name,int score)
    {
        this.name=name;
        this.score=score;
    }

  public String toString(){
        return String.format("{%s:score=====%d}",name,score);
    }
}